#include<iostream>
#include<vector>
#include<unordered_map>
using namespace std;

class Solution {
public:
    int minimumRounds(vector<int>& tasks)
    {
        unordered_map<int, int> hash;
        for (auto e : tasks)
            hash[e]++;
        int round = 0;
        for (auto it = hash.begin(); it != hash.end(); it++)
        {
            int x = it->second;
            if (x == 0)
                continue;
            else if (x == 1)
                return -1;
            else if (x == 2)
                round++;
            else if (x == 3)
                round++;
            else if (x % 3 == 0)
                round += x / 3;
            else
                round += x / 3 + 1;
        }
        return round;
    }
};